/* jshint indent: 2 */
module.exports = (app) => {
  const sequelize = app.model;
  const DataTypes = app.Sequelize.DataTypes;
  const Ad = sequelize.define('ad', {
    id: {
      type: DataTypes.INTEGER(11),
      allowNull: false,
      primaryKey: true,
      autoIncrement: true,
    },
    creatorId: {
      field: 'creator_id',
      type: DataTypes.INTEGER(11),
      comment: '创建者',
    },
    link: {
      type: DataTypes.STRING(1000),
      comment: '调整链接',
    },
    position: {
      type: DataTypes.INTEGER(1),
      comment: '位置，1：上方，2：侧方',
    },
    img: {
      type: DataTypes.STRING(1000),
      comment: '广告图',
    },
  }, {
    createdAt: 'create_time', // 记录创建时间
    updatedAt: 'update_time', // 记录更新时间
    freezeTableName: true, // 不允许修改表名
  });

  Ad.associate = () => {
    app.model.Ad.belongsTo(app.model.User, {
      as: 'creator',
      foreignKey: 'creatorId',
    });
  };
  return Ad;
};
